unit Init;

{$mode objfpc}{$H+}

//========================================================================================
//
// Unit : init.pas
//
// Description : This module provides
//
// Called By : Main : TfrmMain.FormShow
//
// Calls : AppSettings : frmAppSettings.ApplicationName.GetApplicationName
//                       frmAppSettings.ApplicationNameettings.SetApplicationName
//         HUSplashAbout : procedure TfrmAppSettings.bbtCancelClick
//
// Ver. : 1.00
//
// Date : 27 Dec 2016
//
//========================================================================================


interface

uses
  Classes, Dialogs, SysUtils,
  // Application units
  AppSettings, HUSplashAbout;

function Initialise: boolean;

implementation

//========================================================================================
//          PRIVATE CONSTANTS
//========================================================================================

//========================================================================================
//          PUBLIC CONSTANTS
//========================================================================================

//========================================================================================
//          PRIVATE VARIABLES
//========================================================================================

//========================================================================================
//          PUBLIC VARIABLES
//========================================================================================

//========================================================================================
//          PRIVATE ROUTINES
//========================================================================================

//========================================================================================
//          PUBLIC ROUTINES
//========================================================================================
function Initialise: boolean;
var
  vstrTStr : string;
begin

    dlgSplashAbout.ShowSplash;

    // First we get the Appication path
    GetDir(0, vstrTStr);
    frmAppSettings.AppPath := vstrTStr;

    // If the Application settings.ini file does not exists then this is an initial
    // installation so we read the Inno Setup ASLSetup.ini file that contains the initial
    // default Data and Tanks paths. After the initial setup, the initial data is then
    // maintained and loaded by the ASL.exe application from the Settings.ini and will
    // track any changes in the Data and Tanks directories made by the user.

{    // If the ASL Setup file does not exist we have a major problem and cannot continue
    if not frmSettings.ASLSetupFileExists then
    begin
      showmessage('Unrecoverable error - ASLSetup file not found');
      Result := False;
      Exit;
    end;// if not frmSettings.ASLSetupFileExists

    // If the ASL.ini file does not exist then this is an Initial installation and we have
    // to create the Defaul ASL Data and Tank directories.
   if not frmSettings.ASLSettingsFileExists then
      frmSettings.ReadASLSetupFile;

    // Now we read the ASL.ini Setngs file
    frmSettings.ReadASLSettingsFile;

    // Connect to the Application Database
    if  not dmASLData.ConnectASLDB then
    begin
      showmessage('Application Terminating');
      Result := False;
      Exit;
    end;


    // Now we load the last used Tank file if coonfigured to do so
    // ******** Add code here  }



   // We have had a successful Initialization
  Result := True;

end;// function Initialise

//========================================================================================
//          PROPERTY ROUTINES
//========================================================================================

//========================================================================================
//          MENU ROUTINES
//========================================================================================

//========================================================================================
//          COMMAND BUTTON ROUTINES
//========================================================================================

//========================================================================================
//          CONTROL ROUTINES
//========================================================================================

//========================================================================================
//          FILE ROUTINES
//========================================================================================

//========================================================================================
end.// unit Init

